#!/usr/bin/perl
#
# compile vc++ projects for netbarvideo 
#


&main;


sub main() {
	if ($#ARGV < 2) {
		help();
		return;
	} elsif ($ARGV[0] ne "build" and $ARGV[0] ne "rebuild" and $ARGV[0] ne "clean") {
		help();
		return;
	} elsif ($ARGV[1] ne "debug" and $ARGV[1] ne "release") {
		help();
		return;
	}

	if ($ARGV[2] eq "vmascli") {
		&svnup( "vmas/vmascli" );
		&compile( $ARGV[0], $ARGV[1], "VMAS");
	} elsif ($ARGV[2] eq "vmasinstall") {
		&svnup( "vmas/install/VMASInstall" );
		&compile( $ARGV[0], $ARGV[1], "VMASInstall");
	} elsif ($ARGV[2] eq "vmasunstall") {
		&svnup( "vmas/uninstall" );
		&compile( $ARGV[0], $ARGV[1], "VMASUnInst");
	} elsif ($ARGV[2] eq "vmasuptool") {
		&svnup( "vmas/update/VMASTool" );
		&compile( $ARGV[0], $ARGV[1], "VMASUpTool");
	} elsif ($ARGV[2] eq "vmasupcheck") {
		&svnup( "vmas/update/VMASUpCheck" );
		&compile( $ARGV[0], $ARGV[1], "VMASUpCheck");
	} elsif ($ARGV[2] eq "realplayocx") {
		&svnup( "vmas/vedioctrl/realplay" );
		&compile( $ARGV[0], $ARGV[1], "RealPlayCtrl");
	} elsif ($ARGV[2] eq "playbackocx") {
		&svnup( "vmas/vedioctrl/palyback" );
		&compile( $ARGV[0], $ARGV[1], "PlayBackCtrl");
	} elsif ($ARGV[2] eq "regocx") {
		&svnup( "vmas/regocx" );
		&compile( $ARGV[0], $ARGV[1], "RegOcx");
	} elsif ($ARGV[2] eq "vmasextract") {
		&svnup( "vmas/install/VMASExtract" );
		&compile( $ARGV[0], $ARGV[1], "VMASExtract");
	} else {
		help();
	}
}


sub help() {
	print "usage: perl ./compile.pl [build|rebuild|clean] [debug|release] [project name]\n";
	print "    [project name]: vmascli\n";
	print "    [project name]: vmasinstall\n";
	print "    [project name]: vmasunstall\n";
	print "    [project name]: vmasuptool\n";
	print "    [project name]: vmasupcheck\n";
	print "    [project name]: realplayocx\n";
	print "    [project name]: playbackocx\n";
	print "    [project name]: regocx\n";
	print "    [project name]: vmasextract\n";
	print "    [project name]: chtp\n";
}


sub svnup() {
	my $dir = $_[0];
	my $cmd = "svn up $dir";
	print $cmd, "\n";
	my $ret = `$cmd`;
	print $ret, "\n";
}


sub compile() {
	my ($opt1, $opt2, $projectname) = @_;
	my $cmd = "devenv ../bin/CATIM.sln /$opt1 \"$opt2|Win32\" /project $projectname";
	print $cmd, "\n";
	my $ret = `$cmd`;
	print $ret, "\n";
}


